# -*- coding: utf-8 -*-
# @author: dengxixi
# @date:   2021-05-08
# @file:  简单的TCP客户端
import socket

if __name__ == "__main__":
    sock = socket.socket()
    # 连接服务端
    sock.connect(('127.0.0.1', 999,))
    login_msg = sock.recv(1024)
    print(login_msg.decode('utf-8'))
    while True:
        message = input("[Client] Please input the message:").strip()
        if not message:
            continue
        elif message == "exit":
            sock.sendall(b'exit')
            break
        else:
            sock.sendall(message.encode('utf-8'))
            print("[Client] Waitting for recving message...")
            data = sock.recv(1024)
            print(data.decode('utf-8'))
    sock.close()
